<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>新增用户</title>
		<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/default/easyui.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/icon.css" />" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.2.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/jquery.easyui.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/easyui-lang-zh_CN.js" />"></script>
		<script type="text/javascript">
			$.extend($.fn.validatebox.defaults.rules,{
				checkStaffNo:{					
					validator:function(value, param){						
						if(value.length >= param[0]){
							$.fn.validatebox.defaults.rules.checkStaffNo.message = '工号长度不能越过' + param[0] + "个字符";
							return false;
						}else{
							var result = $.ajax({
								url:param[1],
								data:{'staffNo':value},
								type:'post',
								dataType:'json',
								async:false,
								cache:false
							}).responseText;
							if(result == 'true'){
								$.fn.validatebox.defaults.rules.checkStaffNo.message = '该工号已存在';
								return false;
							}else
								return true;
						}
					},
					message:''
				},
				checkLoginName:{					
					validator:function(value, param){						
						if(value.length >= param[0]){
							$.fn.validatebox.defaults.rules.checkLoginName.message = ' 登录名长度不能越过' + param[0] + "个字符";
							return false;
						}else{
							var result = $.ajax({
								url:param[1],
								data:{'loginName':value},
								type:'post',
								dataType:'json',
								async:false,
								cache:false
							}).responseText;
							if(result == 'true'){
								$.fn.validatebox.defaults.rules.checkLoginName.message = '该登录名已存在';
								return false;
							}else
								return true;
						}
					},
					message:''
				}
			});

		
			$(function(){
				$("#login_password").val('');
				
				if('${result}' != null && '${result}' != ''){
					$.messager.alert('操作结果','${result}!');
				}
			});
			
			function clearForm(){
				$("#user_type").combobox('setValue', '0');
				$("#staff_no").val("");
				$("#login_name").val("");
				$("#login_password").val("");
				$("#operate_password").val("");
				$("#actual_name").val("");
				
				$("#birthdayDate").datebox("setValue","");
				$("input[name='gender'][value=${gender_man}]").attr("checked",true); 
				$("#expiryDate").datebox("setValue"," ");				
				$("input[name='status'][value=${statusActive}]").attr("checked",true);
			}
			
			function submitForm(){
				if( $("input[name='user_type'][checked]").val() == "0"){
					$.messager.alert('新增用户','请选择用户类型!','warning');
					return false;
				}
				
				if($.trim($("#birthdayDate").datebox("getValue")) != ""){
					$("#birthday").val($.trim($("#birthdayDate").datebox("getValue")));
				}
				$("#expiry_date").val($.trim($("#expiryDate").datebox("getValue")));
				
				$("#addUserForm").submit();
			}
			
			
		</script>
	</head>
	
	<body>
		<div class="easyui-panel" title="新增用户" fit="true">
			<div style="padding:10px 0 10px 60px; text-align: right;">
				<form name="addUserForm" id="addUserForm" method="post" action="addUser">
					<table  style="text-align: center; border:1px;width:400px;">
						<tr>
							<td align="right" style="height:28px;">用户类型：</td>
	    					<td align="left">
	    						<select  class="easyui-combobox" style="width:155px;"  name="user_type" id="user_type" data-options="required:true, panelHeight:'auto'">
	    							<option value="0" selected="selected">---请选择---</option>
	    							<c:forEach var="code" items="${userTypeList}">
	    								<option value="${code.id}">${code.name}</option>	
	    							</c:forEach>
	    						</select>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">员工编号：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" 
	    							name="staff_no" id="staff_no" required="true" validType="checkStaffNo['100', 'checkStaffNo.do']" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">登录名：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" name="login_name" id="login_name" data-options="required:true" validType="checkLoginName['100', 'checkLoginName[.do']"/>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">密码：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="password" name="login_password" id="login_password" data-options="required:true" value="" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">操作密码：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="password" name="operate_password" id="operate_password" data-options="required:true" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">姓名：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" name="actual_name" id="actual_name" data-options="required:false" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">生日：</td>
	    					<td align="left">
	    						<input class="easyui-datebox" style="width:155px;" id="birthdayDate"  data-options="required:false " />
	    						<input type="hidden" name="birthday" id="birthday" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">性别：</td>
	    					<td align="left">
	    						<input type="radio" name="gender" id="gender" value="${gender_man}" checked="checked" />男
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="gender" id="gender" value="${gender_woman}" />女
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">有效期：</td>
	    					<td align="left">
	    						<input class="easyui-datebox" style="width:155px;" id="expiryDate" value="&nbsp;&nbsp;" data-options="required:true" />
	    						<input type="hidden" name="expiry_date" id="expiry_date" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">状态：</td>
	    					<td align="left">
	    						<input type="radio" name="status" id="status" value="${statusActive}" checked="checked"/>激活
	    						&nbsp;&nbsp;&nbsp;&nbsp;
	    						<input type="radio" name="status" id="status" value="${statusInactive}" />未激活
	    					</td>
						</tr>
					</table>
				</form>
			</div>
			
			<div style="margin-left:170px;padding:5px">
	    		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">保存</a>
	    		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
	    	</div>
			
		</div>
	</body>
</html>